from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-27 14:08:35.051161
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 27, Dec, 2021
Time: 14:08:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6434
Nobs: 518.000 HQIC: -48.0925
Log likelihood: 6005.79 FPE: 9.72939e-22
AIC: -48.3818 Det(Omega_mle): 8.19121e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356269 0.077568 4.593 0.000
L1.Burgenland 0.099488 0.043469 2.289 0.022
L1.Kärnten -0.115208 0.022438 -5.135 0.000
L1.Niederösterreich 0.180705 0.090335 2.000 0.045
L1.Oberösterreich 0.117056 0.090313 1.296 0.195
L1.Salzburg 0.283176 0.046848 6.045 0.000
L1.Steiermark 0.022147 0.060445 0.366 0.714
L1.Tirol 0.108654 0.048771 2.228 0.026
L1.Vorarlberg -0.081454 0.043047 -1.892 0.058
L1.Wien 0.035178 0.081884 0.430 0.667
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.017590 0.171024 0.103 0.918
L1.Burgenland -0.048151 0.095841 -0.502 0.615
L1.Kärnten 0.035484 0.049471 0.717 0.473
L1.Niederösterreich -0.207378 0.199172 -1.041 0.298
L1.Oberösterreich 0.455728 0.199125 2.289 0.022
L1.Salzburg 0.313761 0.103292 3.038 0.002
L1.Steiermark 0.108018 0.133270 0.811 0.418
L1.Tirol 0.316377 0.107531 2.942 0.003
L1.Vorarlberg 0.011506 0.094912 0.121 0.904
L1.Wien 0.007091 0.180540 0.039 0.969
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220509 0.039529 5.578 0.000
L1.Burgenland 0.092571 0.022152 4.179 0.000
L1.Kärnten -0.005222 0.011434 -0.457 0.648
L1.Niederösterreich 0.225648 0.046035 4.902 0.000
L1.Oberösterreich 0.163372 0.046024 3.550 0.000
L1.Salzburg 0.037704 0.023874 1.579 0.114
L1.Steiermark 0.029971 0.030803 0.973 0.331
L1.Tirol 0.078645 0.024854 3.164 0.002
L1.Vorarlberg 0.056042 0.021937 2.555 0.011
L1.Wien 0.101835 0.041729 2.440 0.015
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153065 0.039132 3.912 0.000
L1.Burgenland 0.042475 0.021929 1.937 0.053
L1.Kärnten -0.012858 0.011319 -1.136 0.256
L1.Niederösterreich 0.156901 0.045572 3.443 0.001
L1.Oberösterreich 0.346892 0.045561 7.614 0.000
L1.Salzburg 0.099672 0.023634 4.217 0.000
L1.Steiermark 0.111693 0.030493 3.663 0.000
L1.Tirol 0.089199 0.024604 3.625 0.000
L1.Vorarlberg 0.055341 0.021717 2.548 0.011
L1.Wien -0.043575 0.041309 -1.055 0.291
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150709 0.073945 2.038 0.042
L1.Burgenland -0.034356 0.041438 -0.829 0.407
L1.Kärnten -0.036648 0.021390 -1.713 0.087
L1.Niederösterreich 0.130991 0.086115 1.521 0.128
L1.Oberösterreich 0.173940 0.086095 2.020 0.043
L1.Salzburg 0.256923 0.044660 5.753 0.000
L1.Steiermark 0.081278 0.057622 1.411 0.158
L1.Tirol 0.134241 0.046493 2.887 0.004
L1.Vorarlberg 0.104428 0.041036 2.545 0.011
L1.Wien 0.041241 0.078059 0.528 0.597
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078337 0.058533 1.338 0.181
L1.Burgenland 0.016159 0.032802 0.493 0.622
L1.Kärnten 0.050952 0.016931 3.009 0.003
L1.Niederösterreich 0.182211 0.068166 2.673 0.008
L1.Oberösterreich 0.330564 0.068150 4.851 0.000
L1.Salzburg 0.051105 0.035352 1.446 0.148
L1.Steiermark -0.004338 0.045612 -0.095 0.924
L1.Tirol 0.127070 0.036802 3.453 0.001
L1.Vorarlberg 0.059680 0.032483 1.837 0.066
L1.Wien 0.109600 0.061789 1.774 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175330 0.070865 2.474 0.013
L1.Burgenland 0.010400 0.039712 0.262 0.793
L1.Kärnten -0.060928 0.020499 -2.972 0.003
L1.Niederösterreich -0.110569 0.082528 -1.340 0.180
L1.Oberösterreich 0.227171 0.082508 2.753 0.006
L1.Salzburg 0.040162 0.042800 0.938 0.348
L1.Steiermark 0.262362 0.055221 4.751 0.000
L1.Tirol 0.489192 0.044556 10.979 0.000
L1.Vorarlberg 0.069755 0.039327 1.774 0.076
L1.Wien -0.099744 0.074808 -1.333 0.182
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.137838 0.078565 1.754 0.079
L1.Burgenland -0.012105 0.044027 -0.275 0.783
L1.Kärnten 0.062961 0.022726 2.770 0.006
L1.Niederösterreich 0.174837 0.091495 1.911 0.056
L1.Oberösterreich -0.072582 0.091474 -0.793 0.428
L1.Salzburg 0.222323 0.047450 4.685 0.000
L1.Steiermark 0.138336 0.061222 2.260 0.024
L1.Tirol 0.054282 0.049397 1.099 0.272
L1.Vorarlberg 0.141346 0.043600 3.242 0.001
L1.Wien 0.155921 0.082936 1.880 0.060
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465320 0.043958 10.586 0.000
L1.Burgenland 0.001940 0.024634 0.079 0.937
L1.Kärnten -0.014355 0.012715 -1.129 0.259
L1.Niederösterreich 0.180477 0.051192 3.525 0.000
L1.Oberösterreich 0.238802 0.051180 4.666 0.000
L1.Salzburg 0.021852 0.026549 0.823 0.410
L1.Steiermark -0.007385 0.034254 -0.216 0.829
L1.Tirol 0.075052 0.027638 2.716 0.007
L1.Vorarlberg 0.055822 0.024395 2.288 0.022
L1.Wien -0.015484 0.046403 -0.334 0.739
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029508 0.092023 0.153546 0.141949 0.070116 0.082539 0.012752 0.208360
Kärnten 0.029508 1.000000 -0.030687 0.134056 0.051890 0.076030 0.454106 -0.077993 0.100770
Niederösterreich 0.092023 -0.030687 1.000000 0.290072 0.105886 0.257816 0.048587 0.148373 0.252817
Oberösterreich 0.153546 0.134056 0.290072 1.000000 0.198213 0.288614 0.153235 0.133668 0.191508
Salzburg 0.141949 0.051890 0.105886 0.198213 1.000000 0.123796 0.059454 0.111475 0.073625
Steiermark 0.070116 0.076030 0.257816 0.288614 0.123796 1.000000 0.131641 0.091024 0.012881
Tirol 0.082539 0.454106 0.048587 0.153235 0.059454 0.131641 1.000000 0.061899 0.126348
Vorarlberg 0.012752 -0.077993 0.148373 0.133668 0.111475 0.091024 0.061899 1.000000 -0.010454
Wien 0.208360 0.100770 0.252817 0.191508 0.073625 0.012881 0.126348 -0.010454 1.000000